package com.liehu.sms.listener;

import com.liehu.sms.util.SendSmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 监听消息队列
 * 消费sms发送短信服务
 */
@Component
@RabbitListener(queues = "sms")
public class SmsListener {
    @Autowired
    private SendSmsUtil sendSmsUtil;

    /**
     * 消费sms
     */
    @RabbitHandler
    public void executeSms(Map<String,String> map){
        String  mobile = map.get("mobile");//获取手机号
        String  checkCode = map.get("checkCode");//获取验证码
        //发送短信
        System.out.println(map);
        sendSmsUtil.sendSms(mobile,checkCode);
    }

}
